#!/usr/bin/python3

from dingtalk import AppKeyClient
from dingtalk.client.api import User
from dingtalk.client.api import Chat
# from dingtalk.model.message import BodyBase
from dingtalk.model.message import TextBody
from dingtalk.model.message import VoiceBody
from dingtalk.client.api import Message
# import dingtalk.api
# from dingtalk import dingtalk.model.message.TextBody

'''先安装dingding模块 pip install dingtalk-sdk'''


CORP_ID = 'dingcab7b27c773be42b35c2f4657eb6378f'
APP_KEY = 'dingy4w7tp7n7un9uqkm'
APP_SECRET = 'lHEt2JgM1_d1Vt-gChoraQyhcCZFPdDQDYZn58GbeXxuiNWTiFUzqitiKpNuRbTw'

client = AppKeyClient(CORP_ID, APP_KEY, APP_SECRET)
responses = client.department.list()
print(responses)

# u = dingtalk.client.api.User()

# access_token = client.get_access_token()
# print(access_token)
u = User(client)
l = u.list(155486215)
print(l)

chatObj = Chat(client)
name = '消息测试群'
owner = 'manager2964'
# useridlist = ['manager2964', '323546073924442183']
# chatId = chatObj.create(name, owner, useridlist)
# print(chatId)

chatId = 'chatdc05b12def3233fef2c7807906ca36e4'

'''发送文本消息'''
# tb = TextBody('在吗？收到回复，谢谢！')
# r = chatObj.send(chatId, tb)
# print(r)

'''上传语音文件'''
# msgObj = Message(client)
# file_path = "D:/download/音乐/谁是大英雄 (《东成西就》电影插曲) - 张学友 (Jacky Cheung).mp3"
# with open(file_path, "rb") as f:
#     upload_result = msgObj.media_upload('voice', f)
#     print(upload_result)

'''发送语音消息'''
medea_id = '@lAXPDeC2vTWdFHzOPKHW0s5c13wJ'
vb = VoiceBody(medea_id, 123)
r = chatObj.send(chatId, vb)
print(r)
